<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no" />
		<title>商家内页</title>
		<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../../css/aui-flex.css" />
		<style type="text/css">
			.coverBg{
				width: 100%;
				background-size: cover;
				position: relative;
			}
			.headerInfo{
				position: absolute;left:0;bottom: 0;
				width: 100%;
				height:65px;
				background: rgba(0,0,0,0.2);
				color:#fff;
				text-shadow: 1px 1px 1px #333;
				font-size:14px;
			}
			.headerInfo .aui-img-object{
				width: 65px;height: 65px;
				margin-right: 10px;
			}
			.headerInfo .leftInfo{
				padding:5px;
			}
			.headerInfo .rightInfo{
				padding:10px 5px 0 0;
			}
			.headerInfo .companyName{
				font-size: 16px;
				margin-bottom: 5px;
			}

			.headerFooter .aui-bar-tab li.active .aui-iconfont,
			.headerFooter .aui-bar-tab li.active p,
			.allPro li.active{
			    color: #327afa;
			}
			.allPro li.active{
				border-color:  #327afa;
			}
			.headerFooter .aui-bar-tab li .aui-iconfont,
			.headerFooter .aui-bar-tab li p{
				color:#666;
			}
			.headerFooter .aui-bar-tab p{
				font-size: 13px;
			}
			.headerFooter .aui-bar-tab .aui-iconfont{
				font-size: 24px !important;
			}
			.headerFooter .aui-bar-tab li.active{
				/*border-bottom: 2px solid #327afa;*/
			}
			.allPro li{
				font-size: 14px;
			}
			.favoriteBtn{
				text-shadow: none;
				font-size: 12px;
			}


			.list-content{
				padding:10px 0;
			}
			.bigPic .divPrice {
				color: #ec2e2e;
				font-weight: bold;
				text-align: left;
				padding-left: 10px !important;
				font-size: 14px;
			}
			.bigPic .divBuy {
				text-align: right;
				padding-right: 10px !important;
				color: #327afa;
				/*font-weight: bold;*/
				font-size: 12px;
				float: right !important;
				color:#9c9c9c;
			}
			.proInfo .aui-img-body{
				height:50px;
				padding:5px !important;
			}
			.bigPic .divPrice, .divBuy {
				padding: 5px;
				overflow: hidden;
			}
			.bigPic .w50 {
				width: 50%;
				float: left;
			}
			.aui-ellipsis-2 {
				display: -webkit-box;
				overflow: hidden;
				text-overflow: ellipsis;
				word-wrap: break-word;
				white-space: normal !important;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}
			.aui-list-view-cell {
				border-radius: 2px;
			}
			/*//一行两列样式*//**/
			.bigPic.aui-list-view.aui-grid-view {
				padding: 0 !important;
				background: #f3f3f3;
			}
			.bigPic.aui-list-view.aui-grid-view .aui-list-view-cell {
				padding: 0 !important;
			}
			.bigPic .aui-col-xs-6:nth-of-type(2n+1) {
				margin-right: 1%;
			}
			.bigPic.aui-list-view.aui-grid-view .aui-list-view-cell .aui-img-body {
				margin: 0 0 0 5px;
				margin-bottom: 1px;
				text-align: left;
			}
			.bigPic li {
				background: #fff !important;
				margin-bottom: 8px;
			}
			.bigPic .aui-col-xs-6 {
				width: 49.5%;
			}
			.bigPic .line {
				width: 90%;
				margin-left: 5%;
			}
			/*一行一列样式*/
			.smallPic .proPic {
				width: 100%;
			}
			.smallPic .divPrice {
				color: #ec2e2e;
				font-weight: bold;
				text-align: left;
				padding-left: 10px !important;
				font-size: 14px;
			}
			.smallPic .divBuy {
				text-align: right;
				padding-right: 10px !important;
				color: #9c9c9c;
				/*font-weight: bold;*/
				font-size: 12px;
				float: right !important;
			}
			.smallPic .divPrice {
				padding: 5px;
				/*padding-top:0px;*/
				overflow: hidden;
				position: absolute;
				bottom: 8px;
			}
			.smallPic .divBuy {
				padding: 5px;
				padding-left: 9px;
				overflow: hidden;
				position: absolute;
				bottom: 30px;
				color:#9c9c9c;
			}
			.smallPic .w50 {
				width: 100%;
				/*float: left;*/
				text-align: left !important;
				line-height: 1;
			}
			.smallPic.aui-list-view.aui-grid-view {
				padding: 0 !important;
				background: #f3f3f3;
			}
			.smallPic.aui-list-view.aui-grid-view .aui-list-view-cell {
				padding: 0 !important;
				padding: 8px !important;
			}
			.smallPic .proPic {
				width: 30%;
				float: left;
			}
			.smallPic .proInfo {
				width: 70%;
				float: left;
			}
			.smallPic .aui-border-b:after {
				border: none;
			}
			.smallPic .aui-col-xs-6:nth-of-type(2n+1) {
				margin-right: 0%;
			}
			.smallPic.aui-list-view.aui-grid-view .aui-list-view-cell .aui-img-body {
				margin: 0px 10px 0 10px;
				text-align: left;
			}
			.smallPic li {
				background: #fff !important;
				margin-bottom: 10px;
			}
			.smallPic .aui-col-xs-6 {
				width: 100%;
			}
			.contain {
				padding: 10px 0 0 0;
			}
			.bigPic0s {
				display: none !important;
			}
			.dongtai {
				display: none;
			}
			.dongtai ul{
				overflow-y: hidden;
			}
			.dongtai .aui-tab-nav li.active{
			    color: #327afa;
			    border-bottom: 2px #327afa solid;
			}
			.dongtai .divHeader{
			    width:40%;
			    margin:0 auto;
			}
			.dongtai ul{
			    background: #f3f3f3;
			}
			.dongtai .aui-list-view .aui-img-object{
			    max-width: 40px;
			    height: 40px;
			}
			.dongtai .aui-list-view .aui-img-object.aui-pull-left{
			    margin-right: 10px;
			}
			.dongtai .aui-list-view-cell{
			    margin-bottom: 15px;
			    background: #fff;
			    margin-top: 8px;
			}
			.dongtai .aui-img-body{
			    float: left;
			    max-width: 195px;
			    white-space: nowrap;
			    overflow: hidden;
			    text-overflow: ellipsis;
			}
			.dongtai .remenType ul{
			    background: #fff;
			}
			.dongtai .aui-list-view:after{
			    border:none;
			}
			.dongtai .type{
			    font-size: 12px;
			    background: #feb77e;
			    color:#fff;
			    padding: 2px 5px;
			}
			.dongtai .title{
			    width: 100%;
			    display: inline-block;
			    margin: 6px;
			}
			.dongtai .conttent img{
			    width: 31%;
			    margin-left:2%;
			    float: left;
			    margin-top: 8px;
			}
			.type2{
				font-size: 12px;
			    color:#fff;
			    padding: 2px 5px;
				background: #78D98E;
			}

			/** 商品动态**/
			.act-title{
				width: 100%;
				display: inline-block;
				margin: 6px;
				word-wrap:break-word;
			}
			.img-item {
				background-color: #eee;
				background-size: cover;
				height:135px;
				margin-right:2%;
				margin-top: 3px;
				float: left;
			}
			.img-item.type1{
				width:82%;
			}
			.img-item.type2{
				width:41%;
			}
			.img-item.type3{
				width:31%;
			}

			.iConent:before {
				content: "\e700" !important;
			}
		</style>
	</head>
	<body>
		<div id="header"></div>
		<div class="list-content prolist" style="display: block;">
			<div id="list-content-1"></div>
		</div>
		<div class="list-content prolist" style="display: none;">
			<div id="list-content-2"></div>
		</div>
		<div class="list-content prolist" style="display: none;">
			<div id="list-content-3"></div>
		</div>
		<div class="list-content dongtai" style="display: none;">
			<ul class="aui-list-view" id="list-content-4"></ul>
		</div>
	</body>
	<script id="header-template" type="text/x-dot-template">
		<div class="coverBg">
			<div class="aui-flex-col headerInfo">
				<div class="aui-flex-item-7" style="padding-right: 0;">					
					<ul>
						<li class="aui-list-view-cell aui-img" style="padding: 0;">
							<img class="aui-img-object aui-pull-left" src="{{=it.company.thumb}}" onclick="go2User({{=it.member.userid}},'../')">
							<div class="aui-img-body leftInfo">
								<div class="companyName aui-ellipsis-1">{{=it.company.company}}</div>
								<div>{{=it.member.regtime}}</div>
							</div>
						</li>
					</ul>
				</div>
				{{?it.member.userid!=0}}
				<div class="aui-flex-item-5 rightInfo aui-clearfix" data-id="{{=it.member.userid}}">
				    {{?!it.member.collect_style}}
				    <div class="aui-btn aui-btn-info aui-pull-right favoriteBtn addFav">收藏</div>
				    {{??}}
				    <div class="aui-btn aui-btn-danger aui-pull-right favoriteBtn cancelFav">取消收藏</div>
				    {{?}}
					<div class="aui-pull-right aui-text-center" style="margin-right: 8px;">
						<div class="collectCount">{{=it.company.collect}}</div>
						<div>粉丝数</div>
					</div>
				</div>
				{{?}}
			</div>
		</div>
		{{?it.member.userid!=0}}
		<div class="aui-nav headerFooter" style="position: relative;">
			<ul class="aui-bar-tab aui-border-b">
				<li class="active" id="tabbar1" data-type="1" data-order="3" data-module="all" tapmode onclick="changeCheck(this)">
					<span class="aui-iconfont aui-icon-shop"></span>
					<p>
						店铺首页
					</p>
				</li>
				<li id="tabbar2" data-type="2" data-order="1" data-module="all" tapmode onclick="changeCheck(this)">
					<span class="aui-iconfont aui-icon-sort"></span>
					<p>
						全部商品
					</p>
				</li>
				<li id="tabbar3"  data-type="3" data-order="2" data-module="new" tapmode onclick="changeCheck(this)">
					<span class="aui-iconfont" style="font-size:17px !important;margin: 1px 0;">NEW</span>
					<p>
						新品上架
					</p>
				</li>
				<li id="tabbar4"  data-type="4" data-module="activity" tapmode onclick="changeCheck(this)">
					<span class="aui-iconfont aui-icon-read"></span>
					<p>
						店铺动态
					</p>
				</li>
			</ul>
		</div>
		<ul class="aui-tab-nav allPro" style="display: none;">
			<li class="active" data-type="1" tapmode onclick="switchChange(this)">
				综合
			</li>
			<li data-type="2" tapmode onclick="switchChange(this)">
				新品
			</li>
			<li data-type="3" tapmode onclick="switchChange(this)">
				销量
			</li>
			<li data-type="4" tapmode onclick="switchChange(this)">
				价格
			</li>
			<li tapmode onclick="changeView(this)" view-type="bigPic">
				<i class="aui-iconfont aui-icon-cascades icon-left-coler"></i>
			</li>
		</ul>
		{{?}}
	</script>


	<script id="myMall-template" type="text/x-dot-template">
		<ul class="aui-list-view aui-grid-view bigPic">
			{{ for(var i in it){ }}
			<li class="aui-list-view-cell aui-img aui-col-xs-6" tapmode onclick="go2Pro({{=it[i].itemid}},'../')">
				<div class="proPic"><img class="aui-img-object" src="{{=it[i].thumb}}">
				</div>
				<div class="proInfo">
					<div class="aui-img-body  aui-ellipsis-2">
						{{=it[i].title}}
					</div>
					<div class="aui-border-b line"></div>
					<div class="divBuy  zfhuise">
						成交<span class="num">{{=it[i].sales}}</span>笔
					</div>
					<div class="divPrice  zfBlue">
						￥<span class="price ">{{=it[i].price}}</span>
					</div>
				</div>
			</li>
			{{ } }}
		</ul>
	</script>
	<script id="newMall-template" type="text/x-dot-template">
		{{ for(var i in it){ }}
		{{? it[i].length > 0}}
		<ul class="aui-list-view aui-grid-view bigPic" style="margin: 0;">
			<p style="padding:5px 12px;">近{{= i }}周上新</p>
			{{ for(var k in it[i]){ }}
			<li class="aui-list-view-cell aui-img aui-col-xs-6"  tapmode onclick="go2Pro({{=it[i].itemid}},'../')">
				<div class="proPic"><img class="aui-img-object" src="{{=it[i][k].thumb}}">
				</div>
				<div class="proInfo">
					<div class="aui-img-body  aui-ellipsis-2">
						{{=it[i][k].title}}
					</div>
					<div class="aui-border-b line"></div>
					<div class="divBuy  zfhuise">
						成交<span class="num">{{=it[i][k].sales}}</span>笔
					</div>
					<div class="divPrice  zfBlue">
						￥<span class="price ">{{=it[i][k].price}}</span>
					</div>
				</div>
			</li>
			{{ } }}
		</ul>
		{{?}}
		{{ } }}
	</script>
	<script id="activity-template" type="text/x-dot-template">
		{{ for(var i in it){ }}
<!-- 		<li class="aui-list-view-cell aui-img bigPic">
			<img class="aui-img-object aui-pull-left" src="{{=it[i].logo}}">
			<div class="aui-img-body">
				{{=it[i].company}}
				<p><span class="time">{{=it[i].addtime}}</span>  浏览<span class="sum">{{=it[i].hit}}</span></p>
			</div>
			{{? it[i].status == 1 }}
			<div class="type aui-pull-right">优惠</div>
			{{?? it[i].status == 2 }}
			<div class="type2 aui-pull-right">上新</div>
			{{?}}
			<div class="title">{{=it[i].title}}</div>
			<div class="conttent">
				<img src="{{=it[i].thumb}}" >
				<img src="{{=it[i].thumb1}}" >
				<img src="{{=it[i].thumb2}}" >
			</div>
		</li> -->

		<li class="aui-list-view-cell aui-img" item-id="{{=it[i].itemid}}" onclick="go2Pro({{=it[i].itemid}},'../')">
			<div class="aui-img-body">
				<p class="post_detail">
					<span class="time">{{=formatMsgTime(it[i].addtime)}}</span>
					<!-- <span class="time">2016-12-1</span> -->
					&nbsp;&nbsp;浏览<span class="sum">{{=it[i].hits}}</span>
				</p>
			</div>
			<!-- <div class="shoucang aui-pull-right {{? it[i].isCollect == 1}}collected{{?}}">
				<span class="type">{{? it[i].isCollect == 1}}已{{?}}收藏</span>
			</div> -->
			<div class="act-title">{{=it[i].title}}</div>
			{{? it[i].thumb }}
			<div class="conttent aui-clearfix">
				{{? it[i].thumb&&!it[i].thumb1 }}
				<div class="img-item type1" style="background-image: url({{=it[i].thumb}});"></div>
				{{?? it[i].thumb&&it[i].thumb1&&!it[i].thumb2}}
				<div class="img-item type2" style="background-image: url({{=it[i].thumb}});"></div>
				<div class="img-item type2" style="background-image: url({{=it[i].thumb1}});"></div>
				{{??}} 
				<div class="img-item type3" style="background-image: url({{=it[i].thumb}});"></div>
				<div class="img-item type3" style="background-image: url({{=it[i].thumb1}});"></div>
				<div class="img-item type3" style="background-image: url({{=it[i].thumb2}});"></div>
				{{?}}
			</div>
			{{?}}
		</li>

		{{ } }}
	</script>


	<script type="text/javascript" src="../../script/api.js" ></script>
	<script type="text/javascript" src="../../script/doT.min.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/jquery-1.11.3.js"></script>
	<script type="text/javascript">
		var page = 1,isLock = false, type=1;
		var companyData;
		var module='index';
		apiready = function() {
			api.parseTapmode();
			getStorageAll();

			companyData=api.pageParam.companyData;

			renderHeader(companyData);
			
			if(companyData&&companyData.member.userid!=0){
				api.setRefreshHeaderInfo({
					visible : true,
					loadingImg : 'widget://image/ptr_pull.png',
					bgColor : '#efeff4',
					textColor : '#959595',
					textDown : '下拉刷新',
					textUp : '松开刷新',
					showTime : true
				}, function(ret, err) {
					isLock=false;
					page = 1;
					// getData();
					showData(type,module);
				});
				// showData(type,module);
				api.refreshHeaderLoading();
			}

			// //重新登录监听
			// api.addEventListener({
			// 	name : 'reGetMyInfo'
			// }, function(ret) {
			// 	if (ret && ret.value) {
			// 		page = 1;
			// 		getData();
			// 	}
			// });
			//监听是否达到底部上拉加载
	        api.addEventListener({
	            name : 'scrolltobottom'
	        }, function(ret, err) {
	        	page++;
	        	if(!isLock){
		        	showData(type,module,page);
	        	}
	        });
			// //排列登录监听
			// api.addEventListener({
			// 	name : 'arrangeType'
			// }, function(ret) {
			// 	if (ret && ret.value) {
			// 		viewType = ret.value.viewType;
			// 		changeView(viewType);
			// 	}
			// });
			// //一级分类监听
			// api.addEventListener({
			// 	name:"reGetMyType"
			// },function(ret){
			// 	if(ret && ret.value){
			// 		typeid = ret.value.typeid;
			// 		module = ret.value.module;
			// 		getData(typeid);
			// 	}
			// })
			// //二级分类监听
			// api.addEventListener({
			// 	name:"mallType"
			// },function(ret){
			// 	if(ret && ret.value){
			// 		typeid = ret.value.typeid;
			// 		getData(typeid);
			// 	}
			// })
		}

		function renderHeader(compnayData){
			var tpl = $api.byId('header-template').text;
			var tempFn = doT.template(tpl);
			$('#header').html(tempFn(compnayData));

			body_h = $api.offset($api.dom('body')).h;
			$('.coverBg').height(body_h/3).css({'background-image':'url('+companyData.company.bgurl+')'});
		}

		//为了在下面的热门类别可以通用，单独出来
		function changeCheck(obj){
			isLock=false;
			page=1;

			$(obj).closest('ul').find("li").removeClass("active");
			$(obj).addClass("active");
			//显示热销或者15天前那些
			var dataType=parseInt($(obj).attr("data-type"));
			var dataOrder=$(obj).attr("data-order");
			var dataModule=$(obj).attr("data-module");
			type=dataType;
			module=dataModule;
			
			// //商品参数更新
			// api.sendEvent({
			// 	name : 'reGetMyType',
			// 	extra : {
			// 		typeid : dataOrder,
			// 		module : dataModule
			// 	}
			// });
			$(".allPro").hide();
			if(dataType==2){
				$(".allPro").show();
			}

			$('.list-content').hide();
			$('#list-content-'+dataType).parent().show();

			// showData(dataType,dataModule);
			api.refreshHeaderLoading();
		}
        function switchChange(obj) {
            $('.aui-tab-nav li').removeClass('active');
            $(obj).addClass('active');
            var type = $(obj).attr('data-type');
            page=1;
            // showData(type,module,page)
            api.refreshHeaderLoading();
        }
        function changeView(obj) {
            var viewType = $(obj).attr("view-type");

            //排列参数更新
            if (viewType == "bigPic") {
                //一行两列
                $(".aui-icon-cascades").addClass("iConent");
                $(obj).attr("view-type", "smallPic");
                //一行两列
                $(".prolist").find("ul").addClass("smallPic");
                $(".prolist").find("ul").removeClass(viewType);
                $(".aui-icon-cascades").addClass("iConent");
            } else if (viewType == "smallPic") {
                //一行一列
                $(".aui-icon-cascades").removeClass("iConent");
                $(obj).attr("view-type", "bigPic");
                //一行一列
                $(".aui-icon-cascades").removeClass("iConent");
                $(".prolist").find("ul").addClass("bigPic");
                $(".prolist").find("ul").removeClass(viewType);
            }

//            if (viewType == "bigPic") {
//                //一行两列
//                $(".aui-icon-cascades").addClass("iConent");
//                $(obj).attr("view-type", "smallPic");
//            } else if (viewType == "smallPic") {
//                //一行一列
//                $(".aui-icon-cascades").removeClass("iConent");
//                $(obj).attr("view-type", "bigPic");
//            }
        }
		function showData(typeid,module,toPage){
			if(isLock)return;
			isLock = true;

			toPage=toPage?toPage:page;
			if(toPage==1)api.refreshHeaderLoading();

			var data = {};
			if(!typeid){typeid = type;}	

			if(module == "activity"){
				var url = 'Factory/storeDynamics';

				data['page'] = toPage;
				data['userName'] = companyData.member.username;
			}else{
				var url = 'category/categoryList';

				data['page'] = toPage;
				data['username'] = companyData.member.username;		
				data['pagetype'] = module=='index'?'all':module;
				data['type'] = typeid==1?2:typeid;
			}

			ajaxRequest(url, 'post', data, function (ret, err) { 
				isLock=false;
				api.refreshHeaderLoadDone();
				if (ret.status == 1) {
					if(module == 'new'){
						var tpl = $api.byId('newMall-template').text;
						ID = 'list-content-3';
					}else if(module == 'activity'){
						var tpl = $api.byId('activity-template').text;
						ID = 'list-content-4';
					}else if(module=='all'){
						var tpl = $api.byId('myMall-template').text;
						ID = 'list-content-2';
					}else{
						var tpl = $api.byId('myMall-template').text;
						ID = 'list-content-1';
					}
					var content = $api.byId(ID);
					var tempFn = doT.template(tpl);
					if (page > 1) {
						if(!$.trim(ret.msg)||module=='new'){
							isLock=true;
							return;
						}
						$api.append(content, tempFn(ret.msg));
					} else {
						$api.html(content, tempFn(ret.msg));
					}
				} else {
					// if (page == 1) {
					// 	$(".kongshuju").show();
					// }
					api.toast({
						msg : ret.msg,
						duration : 2000,
						location : 'bottom'
					});
					isLock=true;
				}
			});
		}

		$(document).ready(function(){
			var isLoading=false;
			$('body').delegate('.addFav','click',function(){
				if(!user_id) {
					openTo('../loginPass_win');
					return;
				}
				if(isLoading)return;
				isLoading=true;

				//添加收藏
				var $this=$(this);
				var id=$this.parent().attr('data-id');
				showLoading();

				var data = {};
				var url = 'factory/collect/userid/' + user_id +'/type/company/id/' + id ; ;
				ajaxRequest(url, 'get', data, function (ret, err) {
					hideLoading();
					isLoading=false;
					if(ret.msg == 1){
						$this.replaceWith('<div class="aui-btn aui-btn-danger aui-pull-right favoriteBtn cancelFav">取消收藏</div>');
						$(".collectCount").text(parseInt($(".collectCount").text())+1);
					}else{
						api.toast({
							msg : ret.msg,
							duration : 2000,
							location : 'bottom'
						});
					}
				});
			}).delegate('.cancelFav','click',function(){
				if(isLoading)return;
				isLoading=true;
				//取消收藏
				var $this=$(this);
				var id=$this.parent().attr('data-id');
				showLoading();

				data = {
					userName: user_name,
					type: 2,
					id: id,
				};
		        url = "User/collectionCancel";
		        ajaxRequest(url, 'post', data, function (ret, err) {
		        	hideLoading();
		        	isLoading=false;
		            if (ret.status == 1) {
		                //发送监听
		                api.sendEvent({
		                    name: 'collectionCancel',
		                    extra: {
		                        key: 'true'
		                    }
		                });

						//发送监听
						api.sendEvent({
							name: 'updateShopFavoriteStatus',
							extra: {
								userid:id
							}
						});

		                $this.replaceWith('<div class="aui-btn aui-btn-info aui-pull-right favoriteBtn addFav">收藏</div>');
                        $(".collectCount").text(parseInt($(".collectCount").text())-1);
		            } else {
		                api.toast({
		                    msg: '取消失败',
		                    duration: 2000,
		                    location: 'bottom'
		                });
		            }
		        });
			})
		});

	</script>
</html>